package cn.iocoder.devlop.module.annual.report.marpripinfo.dal;

import cn.iocoder.devlop.framework.common.pojo.PageResult;
import cn.iocoder.devlop.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.devlop.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.devlop.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.devlop.module.annual.report.entuser.dal.dataobject.EntuserDO;
import cn.iocoder.devlop.module.annual.report.marpripinfo.controller.vo.CheckResp;
import cn.iocoder.devlop.module.annual.report.marpripinfo.controller.vo.MarpripinfoExportReqVO;
import cn.iocoder.devlop.module.annual.report.marpripinfo.controller.vo.MarpripinfoPageReqVO;
import cn.iocoder.devlop.module.annual.report.marpripinfo.dal.dataobject.MarpripinfoDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 企业基本信息 Mapper
 *
 * @author sunhao
 */
@Mapper
public interface MarpripinfoMapper extends BaseMapperX<MarpripinfoDO> {

    default PageResult<MarpripinfoDO> selectPage(MarpripinfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MarpripinfoDO>()
                .eqIfPresent(MarpripinfoDO::getRegno, reqVO.getRegno())
                .likeIfPresent(MarpripinfoDO::getEntname, reqVO.getEntname())
                .likeIfPresent(MarpripinfoDO::getParentname, reqVO.getParentname())
                .eqIfPresent(MarpripinfoDO::getEnttype, reqVO.getEnttype())
                .likeIfPresent(MarpripinfoDO::getEnttypename, reqVO.getEnttypename())
                .eqIfPresent(MarpripinfoDO::getIndustryphy, reqVO.getIndustryphy())
                .likeIfPresent(MarpripinfoDO::getIndustryphyname, reqVO.getIndustryphyname())
                .eqIfPresent(MarpripinfoDO::getOplocdistrict, reqVO.getOplocdistrict())
                .eqIfPresent(MarpripinfoDO::getLerep, reqVO.getLerep())
                .eqIfPresent(MarpripinfoDO::getLegcerno, reqVO.getLegcerno())
                .eqIfPresent(MarpripinfoDO::getTel, reqVO.getTel())
                .eqIfPresent(MarpripinfoDO::getDom, reqVO.getDom())
                .eqIfPresent(MarpripinfoDO::getOploc, reqVO.getOploc())
                .eqIfPresent(MarpripinfoDO::getOpscope, reqVO.getOpscope())
                .eqIfPresent(MarpripinfoDO::getAbuitemco, reqVO.getAbuitemco())
                .eqIfPresent(MarpripinfoDO::getCbuitem, reqVO.getCbuitem())
                .eqIfPresent(MarpripinfoDO::getOpscotype, reqVO.getOpscotype())
                .likeIfPresent(MarpripinfoDO::getOpscotypename, reqVO.getOpscotypename())
                .eqIfPresent(MarpripinfoDO::getOpfrom, reqVO.getOpfrom())
                .eqIfPresent(MarpripinfoDO::getOpto, reqVO.getOpto())
                .eqIfPresent(MarpripinfoDO::getRegcap, reqVO.getRegcap())
                .eqIfPresent(MarpripinfoDO::getReccap, reqVO.getReccap())
                .eqIfPresent(MarpripinfoDO::getRegcapcur, reqVO.getRegcapcur())
                .likeIfPresent(MarpripinfoDO::getRegcapcurname, reqVO.getRegcapcurname())
                .eqIfPresent(MarpripinfoDO::getRegcapusd, reqVO.getRegcapusd())
                .betweenIfPresent(MarpripinfoDO::getEstdate, reqVO.getEstdate())
                .eqIfPresent(MarpripinfoDO::getCongro, reqVO.getCongro())
                .eqIfPresent(MarpripinfoDO::getCongrousd, reqVO.getCongrousd())
                .eqIfPresent(MarpripinfoDO::getCompform, reqVO.getCompform())
                .likeIfPresent(MarpripinfoDO::getCompformname, reqVO.getCompformname())
                .eqIfPresent(MarpripinfoDO::getOpstate, reqVO.getOpstate())
                .likeIfPresent(MarpripinfoDO::getOpstatename, reqVO.getOpstatename())
                .eqIfPresent(MarpripinfoDO::getRegorg, reqVO.getRegorg())
                .likeIfPresent(MarpripinfoDO::getRegorgname, reqVO.getRegorgname())
                .betweenIfPresent(MarpripinfoDO::getIssblicdate, reqVO.getIssblicdate())
                .eqIfPresent(MarpripinfoDO::getTimestamp, reqVO.getTimestamp())
                .eqIfPresent(MarpripinfoDO::getUuid, reqVO.getUuid())
                .betweenIfPresent(MarpripinfoDO::getSolrtime, reqVO.getSolrtime())
                .eqIfPresent(MarpripinfoDO::getLegcertype, reqVO.getLegcertype())
                .eqIfPresent(MarpripinfoDO::getUniscid, reqVO.getUniscid())
                .eqIfPresent(MarpripinfoDO::getIndustrytypesmall, reqVO.getIndustrytypesmall())
                .eqIfPresent(MarpripinfoDO::getIsparentgroup, reqVO.getIsparentgroup())
                .likeIfPresent(MarpripinfoDO::getGroupname, reqVO.getGroupname())
                .eqIfPresent(MarpripinfoDO::getGroupshorter, reqVO.getGroupshorter())
                .eqIfPresent(MarpripinfoDO::getEnttypepro, reqVO.getEnttypepro())
                .eqIfPresent(MarpripinfoDO::getFretradis, reqVO.getFretradis())
                .orderByDesc(MarpripinfoDO::getId));
    }

    default List<MarpripinfoDO> selectList(MarpripinfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MarpripinfoDO>()
                .eqIfPresent(MarpripinfoDO::getRegno, reqVO.getRegno())
                .likeIfPresent(MarpripinfoDO::getEntname, reqVO.getEntname())
                .likeIfPresent(MarpripinfoDO::getParentname, reqVO.getParentname())
                .eqIfPresent(MarpripinfoDO::getEnttype, reqVO.getEnttype())
                .likeIfPresent(MarpripinfoDO::getEnttypename, reqVO.getEnttypename())
                .eqIfPresent(MarpripinfoDO::getIndustryphy, reqVO.getIndustryphy())
                .likeIfPresent(MarpripinfoDO::getIndustryphyname, reqVO.getIndustryphyname())
                .eqIfPresent(MarpripinfoDO::getOplocdistrict, reqVO.getOplocdistrict())
                .eqIfPresent(MarpripinfoDO::getLerep, reqVO.getLerep())
                .eqIfPresent(MarpripinfoDO::getLegcerno, reqVO.getLegcerno())
                .eqIfPresent(MarpripinfoDO::getTel, reqVO.getTel())
                .eqIfPresent(MarpripinfoDO::getDom, reqVO.getDom())
                .eqIfPresent(MarpripinfoDO::getOploc, reqVO.getOploc())
                .eqIfPresent(MarpripinfoDO::getOpscope, reqVO.getOpscope())
                .eqIfPresent(MarpripinfoDO::getAbuitemco, reqVO.getAbuitemco())
                .eqIfPresent(MarpripinfoDO::getCbuitem, reqVO.getCbuitem())
                .eqIfPresent(MarpripinfoDO::getOpscotype, reqVO.getOpscotype())
                .likeIfPresent(MarpripinfoDO::getOpscotypename, reqVO.getOpscotypename())
                .eqIfPresent(MarpripinfoDO::getOpfrom, reqVO.getOpfrom())
                .eqIfPresent(MarpripinfoDO::getOpto, reqVO.getOpto())
                .eqIfPresent(MarpripinfoDO::getRegcap, reqVO.getRegcap())
                .eqIfPresent(MarpripinfoDO::getReccap, reqVO.getReccap())
                .eqIfPresent(MarpripinfoDO::getRegcapcur, reqVO.getRegcapcur())
                .likeIfPresent(MarpripinfoDO::getRegcapcurname, reqVO.getRegcapcurname())
                .eqIfPresent(MarpripinfoDO::getRegcapusd, reqVO.getRegcapusd())
                .betweenIfPresent(MarpripinfoDO::getEstdate, reqVO.getEstdate())
                .eqIfPresent(MarpripinfoDO::getCongro, reqVO.getCongro())
                .eqIfPresent(MarpripinfoDO::getCongrousd, reqVO.getCongrousd())
                .eqIfPresent(MarpripinfoDO::getCompform, reqVO.getCompform())
                .likeIfPresent(MarpripinfoDO::getCompformname, reqVO.getCompformname())
                .eqIfPresent(MarpripinfoDO::getOpstate, reqVO.getOpstate())
                .likeIfPresent(MarpripinfoDO::getOpstatename, reqVO.getOpstatename())
                .eqIfPresent(MarpripinfoDO::getRegorg, reqVO.getRegorg())
                .likeIfPresent(MarpripinfoDO::getRegorgname, reqVO.getRegorgname())
                .betweenIfPresent(MarpripinfoDO::getIssblicdate, reqVO.getIssblicdate())
                .eqIfPresent(MarpripinfoDO::getTimestamp, reqVO.getTimestamp())
                .eqIfPresent(MarpripinfoDO::getUuid, reqVO.getUuid())
                .betweenIfPresent(MarpripinfoDO::getSolrtime, reqVO.getSolrtime())
                .eqIfPresent(MarpripinfoDO::getLegcertype, reqVO.getLegcertype())
                .eqIfPresent(MarpripinfoDO::getUniscid, reqVO.getUniscid())
                .eqIfPresent(MarpripinfoDO::getIndustrytypesmall, reqVO.getIndustrytypesmall())
                .eqIfPresent(MarpripinfoDO::getIsparentgroup, reqVO.getIsparentgroup())
                .likeIfPresent(MarpripinfoDO::getGroupname, reqVO.getGroupname())
                .eqIfPresent(MarpripinfoDO::getGroupshorter, reqVO.getGroupshorter())
                .eqIfPresent(MarpripinfoDO::getEnttypepro, reqVO.getEnttypepro())
                .eqIfPresent(MarpripinfoDO::getFretradis, reqVO.getFretradis())
                .orderByDesc(MarpripinfoDO::getId));
    }

    @TenantIgnore
    default CheckResp checkMarpripinfo(String regno){
        MPJLambdaWrapper<MarpripinfoDO> marpripinfoDOMPJLambdaWrapper = new MPJLambdaWrapper<>();
        marpripinfoDOMPJLambdaWrapper.selectAll(MarpripinfoDO.class)
                .disableLogicDel()
                .disableSubLogicDel()
                .leftJoin(EntuserDO.class, on -> on
                        .eq(MarpripinfoDO::getUniscid,EntuserDO::getUniscid).or().eq(MarpripinfoDO::getRegno,EntuserDO::getRegno))
                .selectAs(EntuserDO::getMarprid, CheckResp::getMarprid)
                .selectAs(EntuserDO::getLogincode, CheckResp::getLogincode)
                .selectAs(EntuserDO::getLoginpwd, CheckResp::getLoginpwd)
                .selectAs(EntuserDO::getLinkman, CheckResp::getLinkman)
                .selectAs(EntuserDO::getIdeneffeno, CheckResp::getIdeneffeno)
                .selectAs(EntuserDO::getPhone, CheckResp::getPhone)
                .selectAs(EntuserDO::getEmail, CheckResp::getEmail)
                .selectAs(EntuserDO::getFromtype, CheckResp::getFromtype)
                .selectAs(EntuserDO::getCreatedate, CheckResp::getCreatedate)
                .selectAs(EntuserDO::getUpdatetime, CheckResp::getUpdatetime)
                .selectAs(EntuserDO::getLlydept, CheckResp::getLlydept)
                .selectAs(EntuserDO::getLlytel, CheckResp::getLlytel)
                .selectAs(EntuserDO::getCertype, CheckResp::getCertype)
                .eq(MarpripinfoDO::getUniscid,regno)
                .or().eq(MarpripinfoDO::getRegno,regno);
        return selectJoinOne(CheckResp.class, marpripinfoDOMPJLambdaWrapper);
    }

    default MarpripinfoDO selectByRegno(String regno){
        MPJLambdaWrapper<MarpripinfoDO> marpripinfoDOMPJLambdaWrapper = new MPJLambdaWrapper<>();
        marpripinfoDOMPJLambdaWrapper.selectAll(MarpripinfoDO.class)
                .disableLogicDel()
                .disableSubLogicDel()
                .eq(MarpripinfoDO::getRegno,regno)
                .or()
                .eq(MarpripinfoDO::getUniscid,regno);
        return selectJoinOne(MarpripinfoDO.class, marpripinfoDOMPJLambdaWrapper);
    }

    List<MarpripinfoDO> selectChildren(String regno);
}
